﻿<View:LayoutAwarePage x:Name="pageRoot"
                      x:Class="WinRTClient.Views.TimetableView"
                      IsTabStop="false"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                      xmlns:View="using:StyleMVVM.View"
                      xmlns:Converter="using:WinRTClient.Model.Converter"
                      xmlns:DesignData="using:dot_in.HTWKAidStation.Client.DesignData"
                      View:ViewModel.Name="TimetableViewModel"
                      mc:Ignorable="d">
    <Page.Resources>
        <DesignData:TimetableDesignData x:Key="DesignData" />
        <CollectionViewSource x:Key="ViewSource"
                              Source="{Binding Days}"
                              d:Source="{Binding Source={StaticResource DesignData}, Path=Days}"
                              IsSourceGrouped="True"
                              ItemsPath="Events" />
        <Converter:BoolToVisibilityConverter x:Key="BoolVisibConverter" />
    </Page.Resources>
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton"
                    Click="GoBack"
                    IsEnabled="{Binding Navigation.CanGoBack}"
                    Style="{StaticResource BackButtonStyle}" />
            <TextBlock x:Name="pageTitle"
                       Grid.Column="1"
                       Text="TimetableView"
                       Style="{StaticResource PageHeaderTextStyle}" />
        </Grid>
        <Grid Grid.Row="1">
            <GridView ItemsSource="{Binding Source={StaticResource ViewSource}}"
                      SelectionMode="None"
                      IsSwipeEnabled="False"
                      View:AttachedEventCommand.Event="ItemClick"
                      View:AttachedEventCommand.Command="{Binding ItemClickCommand}"
                      IsItemClickEnabled="True">
                <GridView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Horizontal"
                                                Margin="20,0" />
                    </ItemsPanelTemplate>
                </GridView.ItemsPanel>
                <GridView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.ContainerStyle>
                            <Style TargetType="GroupItem">
                                <Setter Property="Margin"
                                        Value="13,0" />
                            </Style>
                        </GroupStyle.ContainerStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DateString}"
                                           Style="{StaticResource HeaderTextStyle}" />
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </GridView.GroupStyle>
                <GridView.ItemTemplate>
                    <DataTemplate>
                        <Border Background="#6B6B6B">
                            <Grid Width="400"
                                  Margin="8"
                                  Height="120">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="36" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <TextBlock Text="{Binding Description}"
                                           Style="{StaticResource SubheaderTextStyle}"
                                           TextTrimming="None"
                                           TextWrapping="NoWrap" />
                                <Rectangle Fill="White"
                                           Height="1"
                                           VerticalAlignment="Bottom" />
                                <StackPanel Grid.Row="1"
                                            Margin="8,0,0,0"
                                            Orientation="Horizontal">
                                    <TextBlock Text="{Binding Room}"
                                               Style="{StaticResource CaptionTextStyle}" />
                                    <TextBlock Text="-"
                                               Margin="4,0"
                                               Style="{StaticResource CaptionTextStyle}" />
                                    <TextBlock Text="{Binding EventType}"
                                               Style="{StaticResource CaptionTextStyle}" />
                                </StackPanel>
                                <TextBlock Grid.Row="2"
                                           Text="{Binding HostName}"
                                           Margin="8" />
                                <StackPanel Orientation="Horizontal"
                                            Grid.Row="2"
                                            VerticalAlignment="Bottom"
                                            HorizontalAlignment="Right">
                                    <TextBlock Text="{Binding StartTimeString}"
                                               Style="{StaticResource TitleTextStyle}" />
                                    <TextBlock Text="-"
                                               Style="{StaticResource TitleTextStyle}"
                                               Margin="4,0" />
                                    <TextBlock Text="{Binding EndTimeString}"
                                               Style="{StaticResource TitleTextStyle}" />
                                </StackPanel>
                            </Grid>
                        </Border>
                    </DataTemplate>
                </GridView.ItemTemplate>
            </GridView>
        </Grid>
        <ProgressBar IsIndeterminate="{Binding IsBusy}"
                     Grid.Row="1"
                     Visibility="{Binding IsBusy, Converter={StaticResource BoolVisibConverter}}"
                     VerticalAlignment="Center" />
    </Grid>
</View:LayoutAwarePage>
